package com.literature.threeGroup.controller;

import com.literature.threeGroup.pojo.MenuRole;
import com.literature.threeGroup.pojo.Role;
import com.literature.threeGroup.service.RoleService;
import com.literature.threeGroup.util.PageResult;
import com.literature.threeGroup.util.Result;
import com.literature.threeGroup.util.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.net.UnknownHostException;
import java.util.List;

/**
 * @author VULCAN
 * @create 2020-01-07 14:31
 * @desc
 **/
@RestController
@CrossOrigin
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
      * @name  角色列表
     * @Author VULCAN
     * @Date 2020/1/10 8:44
     */
    @RequestMapping(value = "findallrole",method = RequestMethod.GET)
    public List<Role> findallrole(){
        List<Role> findall = roleService.findallrole();
        return findall;
    }
    /**
      * @name  角色添加
     * @Author VULCAN
     * @Date 2020/1/10 8:44
     */
    @RequestMapping(value = "roleinsert",method = RequestMethod.POST)
    public void roleinsert(@RequestBody Role role){
        roleService.insertrole(role);
    }
    /**
      * @name  统计数量
     * @Author VULCAN
     * @Date 2020/1/10 18:52
     */
    @RequestMapping(value = "findallrolecount",method = RequestMethod.GET)
    public List<Role> findallrolecount(){
        List<Role> findall = roleService.findallrolecount();
        return findall;
    }
    /**
     * @name  分页 模糊
     * @Author VULCAN
     * @Date 2020/1/10 19:59
     */
    @RequestMapping(value = "findallrolenamecount/{pageNum}/{pageSize}",method = RequestMethod.POST)
    public Result findallrolenamecount(@RequestBody Role role, @PathVariable("pageNum") int pageNum , @PathVariable("pageSize") int pageSize){
        PageResult findallpage = roleService.findallrolenamecount(role,pageNum, pageSize);
        return new Result(true, StatusCode.OK,"查询成功",findallpage) ;
    }
    /**
     * @name  批量删除
     * @Author VULCAN
     * @Date 2020/1/17 9:47
     */
    @RequestMapping(value = "rolebulkdel/{id}",method = RequestMethod.GET)
    public String rolebulkdel(@PathVariable String id) throws UnknownHostException {
        String[] ids = id.split(",");
        System.out.println(ids);
        return roleService.rolebulkdel(ids);
    }
    /**
     * @name  添加角色
     * @Author VULCAN
     * @Date 2020/1/17 9:47
     */
    @RequestMapping(value = "rolebulkadd/{id}",method = RequestMethod.POST)
    public void rolebulkadd(@PathVariable String id,@RequestBody Role role) throws UnknownHostException {
        String[] ids = id.split(",");
        System.out.println(role);
        roleService.rolebulkadd(ids,role);
    }
    /**
     * @name  根据id查询
     * @Author VULCAN
     * @Date 2020/1/9 19:27
     */
    @RequestMapping(value = "findbyroleid/{roleId}",method = RequestMethod.GET)
    public Role findbyroleid(@PathVariable("roleId") String roleId){
        return roleService.findbyroleid(roleId);
    }
    /**
     * @name  修改数据
     * @Author VULCAN
     * @Date 2020/1/9 19:27
     */
    @RequestMapping(value = "roleupdate/{id}",method = RequestMethod.POST)
    public void roleupdate(@PathVariable String id,@RequestBody Role role) throws UnknownHostException {
        String[] ids = id.split(",");
        System.out.println(role);
        roleService.roleupdate(ids,role);
//        roleService.roleupdate(role);
    }
    /**
     * @name  根据id查询
     * @Author VULCAN
     * @Date 2020/1/9 19:27
     */
    @RequestMapping(value = "findbyrolemenuid/{roleId}",method = RequestMethod.GET)
    public List<MenuRole> findbyrolemenuid(@PathVariable("roleId") String roleId){
        return roleService.findbyrolemenuid(roleId);
    }
    /**
     * @name  rolecount
     * @Author VULCAN
     * @Date 2020/1/28 14:25
     */
    @RequestMapping(value = "rolecount",method = RequestMethod.GET)
    public List rolecount(){
        return roleService.rolecount();
    }
}
